package com.sloth.bear.controller;

import com.sloth.bear.dto.request.DocumentItemRequest;
import com.sloth.bear.dto.vo.DocumentItemVo;
import com.sloth.bear.service.DocItemService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 文档子项管理
 */
@RestController
@RequestMapping("/document-item")
@RequiredArgsConstructor
public class DocItemController {

    private final DocItemService docItemService;

    /**
     * 创建文档子项
     */
    @PostMapping
    public DocumentItemVo createItem(@Valid @RequestBody DocumentItemRequest request) {
        return docItemService.createItem(request);
    }

    /**
     * 根据ID获取子项详情
     */
    @GetMapping("/{id}")
    public DocumentItemVo getItemById(@PathVariable Long id) {
        return docItemService.getItemById(id);
    }

    /**
     * 更新文档子项
     */
    @PutMapping("/{id}")
    public DocumentItemVo updateItem(@PathVariable Long id, @Valid @RequestBody DocumentItemRequest request) {
        return docItemService.updateItem(id, request);
    }

    /**
     * 删除文档子项
     */
    @DeleteMapping("/{id}")
    public boolean deleteItem(@PathVariable Long id) {
        return docItemService.deleteItem(id);
    }
}